#include "CSerialPort.h"
#include "plane.h"
#include <thread>
#include "getAmmo.h"

using namespace std;

static unsigned char re_msg =  0x03 ;//���ڽ��ܵ�flag
char mode = 0x02;//ģʽ�л���0Ϊ��1Ϊ
void ReadSerial();

int fd;
fd_set fs_read;
struct termios option;
CSerialPort myserialport(fd, option, fs_read);      //�򿪴���

int main()
{

	std::thread *read_thresd = new std::thread(ReadSerial);

	while (true)
	{
		cout<<char(mode+0x30)<<endl;
		if (mode == 0x02)//getAmmo
		{
			SimpleOpenNIViewer getammo;
			getammo.run();
			
		}
		if(mode ==0x03)//pplane
		{
			FindPlane plane;
			plane.plane_run();
		}
	}
}

void ReadSerial()
{
	while (1)
	{
		int n = myserialport.readFromCom_uchar(&re_msg,1);
		//if(n > 0)		
		//cout<<re_msg;
		if (re_msg == 0x01)
		{
			mode = 0x01;
		}
		else if (re_msg == 0x02)
		{
			mode = 0x02;
		}
		else if(re_msg == 0x03)
		{
			mode = 0x03;
		}
		usleep(1000);
	}
}
